package com.yc.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.yc.vo.Result;
import org.apache.ibatis.annotations.*;
import com.yc.entity.TeacherDelays;
import org.springframework.security.core.parameters.P;

import java.util.List;
import java.util.Map;

/**
 * 老师上课迟到表;(teacher_delays)表数据库访问层
 * @date : 2023-6-28
 */
@Mapper
public interface TeacherDelaysMapper  extends BaseMapper<TeacherDelays>{
    /**
     * 分页查询指定行数据
     *
     * @param page 分页参数
     * @param wrapper 动态查询条件
     * @return 分页对象列表
     */
    IPage<TeacherDelays> selectByPage(IPage<TeacherDelays> page , @Param(Constants.WRAPPER) Wrapper<TeacherDelays> wrapper);

    /**
     * 班长将举报老师迟到数据提交
     * @param id
     * @return
     */
    @Update("update teacher_delays set status = 1 where id =#{id}")
    void updateStatus(int id);
    /**
     * 班长将举报老师迟到数据驳回
     * @param id
     * @return
     */
    @Update("update teacher_delays set status = 2 where id =#{id}")
    void updateStatusFale(int id);

    /**
     * 根据班级Id 课程名称 查出教师信息
     * @return
     */
    @Select("select DISTINCT teacherId from schedule where classId = #{classId} and classtime = #{classtime} and date LIKE CONCAT(#{date},'%') ")
    Integer queryTeacher(@Param("classId") int classId,@Param("classtime") String classtime,@Param("date")String date);

    /**
     * 班长查询举报信
     * @param stuid
     * @return
     */


//        @Select("SELECT s.nickname, t.delaydate, t.remarks, i.sname, e.coursename, t.status, t.id \n" +
//                "FROM systemuser s\n" +
//                "INNER JOIN teacher_delays t ON s.id = t.teacherId \n" +
//                "INNER JOIN student_info i ON t.stuid = i.stuid \n" +
//                "INNER JOIN schedule e ON t.scheduleId = e.id\n" +
//                "WHERE t.cid = (SELECT cid FROM student_info WHERE stuid = #{stuid})\n" +
//                "AND t.delaydate >= CURDATE() - INTERVAL 1 WEEK\n" +
//                "AND t.delaydate <= CURDATE()\n" +
//                "ORDER BY t.status, t.delaydate desc ")
    List<Map<String,Object>> queryInfoTea(@Param("stuid") String stuid);

    /**
     * 领导查看已提交教师迟到数据
     * @return
     */
//    @Select("SELECT s.nickname, t.delaydate, t.remarks, i.sname, e.coursename, t.status, t.id\n" +
//            "            FROM systemuser s\n" +
//            "           INNER JOIN teacher_delays t ON s.id = t.teacherId\n" +
//            "            INNER JOIN student_info i ON t.stuid = i.stuid\n" +
//            "            INNER JOIN schedule e ON t.scheduleId = e.id\n" +
//            "            AND t.`status` = '1' AND t.delaydate LIKE CONCAT(#{date}, '%') ORDER BY t.delaydate desc")
    List<Map<String,Object>> managerquery(@Param("date") String date);

    /**
     * 查询老师迟到总数量 根据日期变化
     * @param date
     * @return
     */
//    @Select("SELECT count(*)\n" +
//            "FROM systemuser s\n" +
//            "INNER JOIN teacher_delays t ON s.id = t.teacherId\n" +
//            "INNER JOIN student_info i ON t.stuid = i.stuid\n" +
//            "INNER JOIN schedule e ON t.scheduleId = e.id\n" +
//            "AND t.`status` = '1' AND t.delaydate LIKE CONCAT(#{date}, '%') ")
    int queryTotal(@Param("date") String date);

    /**
     * 添加教师迟到数据
     * @param teacherId
     * @param scheduleId
     * @param delaydate
     * @param stuid
     * @param remarks
     */
    @Insert("insert into teacher_delays (id,teacherId,scheduleId,delaydate,stuid,cid,status,remarks,updateBy,updateTime,createTime,createBy) values (default,#{teacherId},#{scheduleId},#{delaydate},#{stuid},#{cid}, #{status},#{remarks},#{stuid},now(),now(),#{stuid})")
    void insertTeacher(@Param("teacherId") int teacherId,@Param("scheduleId") int scheduleId,@Param("delaydate") String delaydate,@Param("stuid") String stuid,@Param("cid")int cid,@Param("status") int status,@Param("remarks") String remarks);

//    @Select("select COUNT(*) from teacher_delays where `status` = 0  AND cid = (select cid from student_info where stuid = '19020440235')AND delaydate >= DATE_SUB(CURRENT_DATE(), INTERVAL 7 DAY)\n" +
//            "AND delaydate <= CURRENT_DATE()" )
    int queryCount(@Param("stuid") String stuid);

}
